package guda.stark.biz.impl;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

import guda.stark.biz.AdminVillageRelBiz;
import guda.stark.dal.dao.AdminVillageRelDAO;
import guda.stark.dal.dataobject.AdminVillageRelDO;
import guda.grape.autogen.common.page.BaseQuery;
import guda.grape.autogen.common.page.BizResult;

public class AdminVillageRelBizImpl implements AdminVillageRelBiz{

    private final static Logger logger = LoggerFactory.getLogger(AdminVillageRelBizImpl.class);

    @Autowired
    private AdminVillageRelDAO adminVillageRelDAO;

    public BizResult detail(long id) {
        BizResult bizResult = new BizResult();
        try{
            AdminVillageRelDO adminVillageRelDO = adminVillageRelDAO.getAdminVillageRelById(id);
            bizResult.data.put("adminVillageRelDO", adminVillageRelDO);
            bizResult.success = true;
        }catch(Exception e){
            logger.error("query AdminVillageRel error",e);
        }
        return bizResult;
}

    public BizResult list(BaseQuery baseQuery) {
        BizResult bizResult = new BizResult();
        try {
            int totalCount = adminVillageRelDAO.countForPage(baseQuery);
            baseQuery.setTotalCount(totalCount);
            List<AdminVillageRelDO> adminVillageRelList = adminVillageRelDAO.selectForPage(baseQuery);
            bizResult.data.put("adminVillageRelList", adminVillageRelList);
            bizResult.data.put("query", baseQuery);
            bizResult.success = true;
        } catch (Exception e) {
            logger.error("view AdminVillageRel list error", e);
        }
            return bizResult;
     }

    public BizResult delete(long id) {
        BizResult bizResult = new BizResult();
        try {
            adminVillageRelDAO.delAdminVillageRelById(id);
            bizResult.success = true;
        } catch (Exception e) {
            logger.error("delete adminVillageRel error", e);
        }
        return bizResult;
    }

    public BizResult create(AdminVillageRelDO adminVillageRelDO) {
        BizResult bizResult = new BizResult();
        try {
            long id = adminVillageRelDAO.insert(adminVillageRelDO);
            bizResult.data.put("id", id);
            bizResult.success = true;
        } catch (Exception e) {
            logger.error("create AdminVillageRel error", e);
        }
        return bizResult;
    }

    @Override
    public BizResult update(AdminVillageRelDO adminVillageRelDO) {
        BizResult bizResult = new BizResult();
        try {
            adminVillageRelDAO.updateByIdSelective(adminVillageRelDO);
            bizResult.success = true;
        } catch (Exception e) {
            logger.error("update AdminVillageRel error", e);
        }
        return bizResult;
    }


}
